/**
 * Copyright (C) 2010 David Simonek <dafesimonek@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ChooseDirPanel.java
 *
 * Created on May 4, 2010, 3:52:23 PM
 */

package org.dafe.partyband.gui.imports;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.openide.util.NbBundle;

/**
 *
 * @author dafe
 */
public class ChooseDirPanel extends javax.swing.JPanel {
    private final ChooseWizardPanel wizardPanel;

    /** Creates new form ChooseDirPanel */
    public ChooseDirPanel(final ChooseWizardPanel wizardPanel) {
        this.wizardPanel = wizardPanel;
        initComponents();

        importDir.getDocument().addDocumentListener(new DocumentListener() {
            public void insertUpdate(DocumentEvent e) {
                wizardPanel.fireChangeEvent();
            }

            public void removeUpdate(DocumentEvent e) {
                wizardPanel.fireChangeEvent();
            }

            public void changedUpdate(DocumentEvent e) {
                wizardPanel.fireChangeEvent();
            }
        });
    }

    @Override
    public String getName() {
        return NbBundle.getMessage(ChooseDirPanel.class, "LBL_ChoosePanel");
    }

    public File getChosenDir () {
        return new File(importDir.getText());
    }

    public boolean isCorrect () {
        return correct.isSelected();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXLabel1 = new org.jdesktop.swingx.JXLabel();
        importDir = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        correct = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();

        jXLabel1.setText(org.openide.util.NbBundle.getMessage(ChooseDirPanel.class, "ChooseDirPanel.jXLabel1.text")); // NOI18N

        importDir.setText(org.openide.util.NbBundle.getMessage(ChooseDirPanel.class, "ChooseDirPanel.importDir.text")); // NOI18N

        jButton1.setText(org.openide.util.NbBundle.getMessage(ChooseDirPanel.class, "ChooseDirPanel.jButton1.text")); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        correct.setSelected(true);
        correct.setText(org.openide.util.NbBundle.getMessage(ChooseDirPanel.class, "ChooseDirPanel.correct.text",new Object[] {})); // NOI18N
        correct.setToolTipText(org.openide.util.NbBundle.getMessage(ChooseDirPanel.class, "ChooseDirPanel.correct.toolTipText",new Object[] {})); // NOI18N
        correct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                correctActionPerformed(evt);
            }
        });

        jLabel1.setText(org.openide.util.NbBundle.getMessage(ChooseDirPanel.class, "ChooseDirPanel.jLabel1.text",new Object[] {})); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(importDir, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1))
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(correct)
                        .addGap(293, 293, 293)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(importDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(correct)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fileChooser.setDialogTitle(NbBundle.getMessage(ChooseDirPanel.class,
                "LBL_ChooseDialogTitle"));
        int result = fileChooser.showDialog(SwingUtilities.getWindowAncestor(this),
                NbBundle.getMessage(ChooseDirPanel.class, "LBL_PerformChoose"));
        if (result == JFileChooser.APPROVE_OPTION) {
            importDir.setText(fileChooser.getSelectedFile().getPath());
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void correctActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_correctActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_correctActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox correct;
    private javax.swing.JTextField importDir;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private org.jdesktop.swingx.JXLabel jXLabel1;
    // End of variables declaration//GEN-END:variables

}
